<?php
/**
 * Created by PhpStorm.
 * User: thanatos
 * Date: 2017/11/5
 * Time: 下午3:27
 */

namespace backend\controllers;


use common\helpers\AjaxHelper;
use common\models\UploadForm;
use yii\web\Controller;
use yii\web\UploadedFile;

class UploadController extends Controller
{
    public function actionUpload()
    {
        $model = new UploadForm(['scenario' => UploadForm::SCENARIO_CREATE]);
        $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
        $model->type = \Yii::$app->request->getBodyParam('type');
        $file_model = $model->upload();
        
        $response = new AjaxHelper;
        $response->data = ['id' => $file_model->file_id, 'file_path'=>$file_model->file_path];
        return $response;
    }
    
    public function actionDelete()
    {
        $response = new AjaxHelper;
        $response->data = [];
        return $response;
    }
    
}